import org.kwis.msp.lcdui.*;
import org.kwis.msp.lwc.*;
import java.lang.Character;

public class ClipTest extends Jlet
{
	protected void startApp(String args[]){
		Display dis = Display.getDefaultDisplay();
		dis.pushCard(new SampleCard());
        }
	protected void destroyApp(boolean b){
	}
};

class SampleCard extends Card
{
	int proc = 0;

	public void paint(Graphics g)
	{
		int width = getWidth();
		int height = getHeight();

		g.setColor(0xffffff);
		g.fillRect(0,0,width,height);

		Image img = null;
		try
		{
			img = Image.createImage("test.gif");
		}
		catch (Exception e) {}

		switch(proc) 
		{
			case 0 :
				g.drawImage(img,0,0,Graphics.TOP); break;
			case 1 :
				g.setClip(0,0,width/2+30,height/2+30); 
				g.drawImage(img,0,0,Graphics.TOP); break;
			case 2 :
				g.setClip(0,0,width/2+30,height/2+30); 
				g.clipRect(width/2,height/2,width/2,height);
				g.drawImage(img,0,0,Graphics.TOP); 
				break;
			case 3 :
				g.setClip(0,0,width/2-5,height/2-5);
				g.drawImage(img,0,0,Graphics.TOP); 

				g.setClip(width/2+5,0,width/2-5,height/2-5);
				g.drawImage(img,0,0,Graphics.TOP); 

				g.setClip(0,height/2+5,width/2-5,height/2-5);
				g.drawImage(img,0,0,Graphics.TOP); 

				g.setClip(width/2+5,height/2+5,width/2-5,height/2-5);
				g.drawImage(img,0,0,Graphics.TOP); 
				break;

		}
		img = null;
	}

	protected boolean keyNotify(int type, int key) 
	{
		if( (Display.getGameAction(key)==EventQueue.RIGHT) && (type == EventQueue.KEY_PRESSED)) {
			if(proc==3) proc = 0;
			else {
				proc++;
			}
			repaint();
		}
		return true;
	}
};
